package Formularios;

import Model.Paciente;
import static Dao.PacienteDao.*;
import javax.swing.JOptionPane;
import static DataBase.DataBase.*;

/**
 *
 * @author Cleiviane
 */
public class Cadastro_Paciente extends javax.swing.JInternalFrame {

    Paciente paciente;

    /** Creates new form Cadastro_Paciente */
    public Cadastro_Paciente() {
        initComponents();
        ConectarDataBase();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtProntuario = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtNome = new javax.swing.JTextField();
        txtCpf = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtDNascimento = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtEndereco = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtDoencas = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        cboSituacao = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        txaDadosClin = new javax.swing.JTextArea();
        jLabel8 = new javax.swing.JLabel();
        botaoSalvar = new javax.swing.JButton();
        botaoExcluir = new javax.swing.JButton();
        botaoCancelar = new javax.swing.JButton();
        botaoNovo = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        txtTelefones = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtCelular = new javax.swing.JTextField();
        botaoAlterar = new javax.swing.JButton();

        setClosable(true);
        setMaximizable(true);
        setTitle("Cadastro de Pacientes - SISAM");
        setFrameIcon(null);
        setName("telaCadastroPacientes"); // NOI18N

        jLabel1.setText("Prontuário:");

        txtProntuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtProntuarioActionPerformed(evt);
            }
        });
        txtProntuario.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtProntuarioFocusLost(evt);
            }
        });

        jLabel2.setText("Nome:");

        txtNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNomeActionPerformed(evt);
            }
        });

        txtCpf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCpfActionPerformed(evt);
            }
        });
        txtCpf.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtCpfFocusLost(evt);
            }
        });

        jLabel3.setText("CPF:");

        txtDNascimento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDNascimentoActionPerformed(evt);
            }
        });

        jLabel4.setText("D. Nasc:");

        jLabel5.setText("Endereço:");

        txtEndereco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEnderecoActionPerformed(evt);
            }
        });

        jLabel6.setText("Doenças Diag:");

        txtDoencas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDoencasActionPerformed(evt);
            }
        });

        jLabel7.setText("Situação:");

        cboSituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione a Situação do Paciente", "Em Tratamento", "Tratamento Finalizado", "Aguardando Retorno", "Aguardando Resultado Exame", "Tratamento Interrompido", "Obito" }));

        txaDadosClin.setColumns(20);
        txaDadosClin.setRows(5);
        jScrollPane1.setViewportView(txaDadosClin);

        jLabel8.setText("Dados Clínic:");

        botaoSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/salvar.jpg"))); // NOI18N
        botaoSalvar.setText("Salvar");
        botaoSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoSalvar.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoSalvar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        botaoExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/excluir.jpg"))); // NOI18N
        botaoExcluir.setText("Excluir");
        botaoExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoExcluir.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoExcluir.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoExcluirActionPerformed(evt);
            }
        });

        botaoCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/cancelar.jpg"))); // NOI18N
        botaoCancelar.setText("Cancelar");
        botaoCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoCancelar.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoCancelar.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        botaoNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/novo.jpg"))); // NOI18N
        botaoNovo.setText("Novo");
        botaoNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoNovo.setPreferredSize(new java.awt.Dimension(40, 23));
        botaoNovo.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        botaoNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoNovoActionPerformed(evt);
            }
        });

        jLabel9.setText("Telefone:");

        txtTelefones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTelefonesActionPerformed(evt);
            }
        });

        jLabel10.setText("Celular:");

        txtCelular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCelularActionPerformed(evt);
            }
        });

        botaoAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Formularios/Imagens/alterar.jpg"))); // NOI18N
        botaoAlterar.setText("Alterar");
        botaoAlterar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botaoAlterar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        botaoAlterar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botaoAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAlterarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel9)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel1)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(22, 22, 22))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7))
                                .addGap(26, 26, 26)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtTelefones)
                                    .addComponent(txtCpf, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                                .addGap(33, 33, 33)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtDNascimento, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                                    .addComponent(txtCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cboSituacao, javax.swing.GroupLayout.Alignment.TRAILING, 0, 536, Short.MAX_VALUE)
                                    .addComponent(txtEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                                    .addComponent(txtDoencas, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)))
                            .addComponent(txtNome, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
                            .addComponent(txtProntuario, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE))
                        .addGap(26, 26, 26))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botaoAlterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botaoSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)))
                .addGap(52, 52, 52))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoAlterar, botaoCancelar, botaoExcluir, botaoNovo, botaoSalvar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProntuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(txtDNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtTelefones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9))
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDoencas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jLabel8))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(botaoAlterar)
                    .addComponent(botaoSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botaoNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {botaoAlterar, botaoCancelar, botaoExcluir, botaoNovo, botaoSalvar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void txtProntuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtProntuarioActionPerformed
            // TODO add your handling code here:
	}//GEN-LAST:event_txtProntuarioActionPerformed

	private void txtCpfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCpfActionPerformed
            
	}//GEN-LAST:event_txtCpfActionPerformed

	private void txtDNascimentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDNascimentoActionPerformed
            // TODO add your handling code here:
	}//GEN-LAST:event_txtDNascimentoActionPerformed

	private void txtEnderecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEnderecoActionPerformed
            // TODO add your handling code here:
	}//GEN-LAST:event_txtEnderecoActionPerformed

	private void txtDoencasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDoencasActionPerformed
            // TODO add your handling code here:
	}//GEN-LAST:event_txtDoencasActionPerformed

	private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed

                paciente = new Paciente();
                paciente.setNome(txtNome.getText());
                paciente.setProntuario(Integer.parseInt(txtProntuario.getText()));
                paciente.setCpf(txtCpf.getText());
                paciente.setEndereco(txtEndereco.getText());
                paciente.setDoencas(txtDoencas.getText());
                paciente.setSituacao(cboSituacao.getSelectedIndex());
                paciente.setData_nasc(txtDNascimento.getText());
                paciente.setTelefone(txtTelefones.getText());
                paciente.setCelular(txtCelular.getText());
                paciente.setDadosClin(txaDadosClin.getText());

            if (txtProntuario.isEditable()) {
                boolean sucesso = inserirPaciente(paciente);
                if(sucesso = true){
                    JOptionPane.showMessageDialog(null, "Paciente cadastrado com sucesso.");
                }else
                    JOptionPane.showMessageDialog(null, "Erro ao Inserir o Paciente.");
                limparCampos();
                destravaCampos();
                botaoAlterar.setEnabled(false);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(false);
                botaoNovo.setEnabled(true);
                botaoSalvar.setEnabled(true);
            } else {
                alterarPaciente(paciente);
                travaCampos();
                botaoAlterar.setEnabled(true);
                botaoCancelar.setEnabled(true);
                botaoExcluir.setEnabled(true);
                botaoNovo.setEnabled(true);
                botaoSalvar.setEnabled(false);
        }


//          DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
//           formatter.format(dataNasc);
	}//GEN-LAST:event_botaoSalvarActionPerformed

	private void botaoExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoExcluirActionPerformed

            if (paciente == null) {
                JOptionPane.showMessageDialog(this, "Selecione alguem para excluir!");
                return;
            } else {
                    boolean result = JOptionPane.showInternalConfirmDialog(this, "Deseja realmente excluir esse cadastro?") == 0;
                    if(result == true){
                        excluirPaciente(paciente.getProntuario());
                        JOptionPane.showMessageDialog(this, "Paciente Excluído com sucesso!");
                        limparCampos();
                        txtProntuario.requestFocusInWindow();
                } else
                    return;
            }
	}//GEN-LAST:event_botaoExcluirActionPerformed

	private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
            if(txtProntuario.getText().isEmpty()){
                    Cadastro_Paciente.this.dispose();
                    botaoAlterar.setEnabled(false);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(false);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    destravaCampos();
            }else
                {
                    botaoAlterar.setEnabled(true);
                    botaoCancelar.setEnabled(false);
                    botaoExcluir.setEnabled(true);
                    botaoNovo.setEnabled(true);
                    botaoSalvar.setEnabled(false);
                    travaCampos();
                }
	}//GEN-LAST:event_botaoCancelarActionPerformed

	private void botaoNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoNovoActionPerformed
            limparCampos();
            destravaCampos();
            txtProntuario.requestFocus();
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(false);
            botaoNovo.setEnabled(false);
            botaoSalvar.setEnabled(true);
	}//GEN-LAST:event_botaoNovoActionPerformed

        private void txtNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNomeActionPerformed
            // TODO add your handling code here:
}//GEN-LAST:event_txtNomeActionPerformed

        private void txtTelefonesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTelefonesActionPerformed
            // TODO add your handling code here:
}//GEN-LAST:event_txtTelefonesActionPerformed

        private void txtProntuarioFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProntuarioFocusLost
            int prontuario = Integer.parseInt(txtProntuario.getText());
            paciente = localizarPacientePorCodigo(prontuario);

            if (paciente != null) {
                txtNome.setText(paciente.getNome());
                txtCpf.setText(paciente.getCpf());
                txtEndereco.setText(paciente.getEndereco());
                txtDoencas.setText(paciente.getDoencas());
                cboSituacao.setSelectedItem(paciente.getSituacao());
                txtDNascimento.setText(paciente.getData_nasc());
                txtTelefones.setText(paciente.getTelefone());
                txaDadosClin.setText(paciente.getDadosClin());
                txtCelular.setText(paciente.getCelular());

                this.travaCampos();
                botaoAlterar.setEnabled(true);
                botaoCancelar.setEnabled(false);
                botaoExcluir.setEnabled(true);
                botaoNovo.setEnabled(true);
                botaoSalvar.setEnabled(false);
            }

        }//GEN-LAST:event_txtProntuarioFocusLost
        private void limparCampos() {
            txtProntuario.setText(null);
            txtNome.setText(null);
            txtCpf.setText(null);
            txtEndereco.setText(null);
            txtDoencas.setText(null);
            cboSituacao.setSelectedItem(null);
            txtDNascimento.setText(null);
            txtTelefones.setText(null);
            txaDadosClin.setText(null);
            txtCelular.setText(null);
        }

        private void travaCampos(){
            txtProntuario.setEditable(false);
            txtNome.setEditable(false);
            txtCpf.setEditable(false);
            txtEndereco.setEditable(false);
            txtDoencas.setEditable(false);
            cboSituacao.setEditable(false);
            txtDNascimento.setEditable(false);
            txtTelefones.setEditable(false);
            txaDadosClin.setEditable(false);
            txtCelular.setEditable(false);
        }

        private void destravaCampos(){
            txtProntuario.setEditable(true);
            txtNome.setEditable(true);
            txtCpf.setEditable(true);
            txtEndereco.setEditable(true);
            txtDoencas.setEditable(true);
            cboSituacao.setEditable(true);
            txtDNascimento.setEditable(true);
            txtTelefones.setEditable(true);
            txaDadosClin.setEditable(true);
            txtCelular.setEditable(true);
        }

        private void txtCelularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCelularActionPerformed
            // TODO add your handling code here:
        }//GEN-LAST:event_txtCelularActionPerformed

        private void txtCpfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtCpfFocusLost
            if(paciente==null){
                String cpf = txtCpf.getText();
                boolean result = validaCpf(cpf);

                if(!result){
                    JOptionPane.showMessageDialog(null, "CPF Invalido");
                    txtCpf.setText(null);
                }else{
                }

            }
        }//GEN-LAST:event_txtCpfFocusLost

        private void botaoAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAlterarActionPerformed
            this.destravaCampos();
            txtProntuario.setEditable(false);
            botaoAlterar.setEnabled(false);
            botaoCancelar.setEnabled(true);
            botaoExcluir.setEnabled(true);
            botaoNovo.setEnabled(false);
            botaoSalvar.setEnabled(true);
        }//GEN-LAST:event_botaoAlterarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAlterar;
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoExcluir;
    private javax.swing.JButton botaoNovo;
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JComboBox cboSituacao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txaDadosClin;
    private javax.swing.JTextField txtCelular;
    private javax.swing.JTextField txtCpf;
    private javax.swing.JTextField txtDNascimento;
    private javax.swing.JTextField txtDoencas;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtProntuario;
    private javax.swing.JTextField txtTelefones;
    // End of variables declaration//GEN-END:variables
}
